package com.dylan.历史.java8.StreamAPI;

import java.util.function.*;

/**
 * Created by Dylan on 2018/7/25.
 */
public class 函数式接口 {

    public static void main(String[] args) {
        // T get();
        Supplier<Employee> supplier = () -> new Employee(1L, "lucy", 3000.0);
        // void accept(T t);
        Consumer<Employee> consumer = e -> System.out.println(e.getName() + ":" + e.getSalary());
        // void accept(T t, U u);
        BiConsumer<Employee, String> biConsumer = (e, s) -> System.out.println(e.getName() + " " + s);
        // boolean test(T t);
        Predicate<Employee> predicate = s -> s.getSalary() > 1000;
        // int applyAsInt(T value);
        ToIntFunction<String> toIntFunction = String::length;
        // long applyAsLong(T value);
        ToLongFunction<Employee> toLongFunction = Person::getId;
        // double applyAsDouble(T value);
        ToDoubleFunction<Employee> toDoubleFunction = Employee::getSalary;
        // R apply(int value);
        IntFunction<int[]> intFunction = i -> new int[]{i};
        // R apply(long value);
        LongFunction<Person> longFunction = l -> new Person(l, "default");
        // R apply(double value);
        DoubleFunction<Employee> doubleFunction = d -> new Employee(1L, "default", d);
        // R apply(T t);
        Function<Employee, String> function = Employee::getName;
        // R apply(T t, U u);
        BiFunction<Long, String, Person> biFunction = (id, name) -> new Person(id, name);
        // T apply(T t);
        UnaryOperator<Integer> unaryOperator = i -> i + 5;
        // T apply(T t, T u);
        BinaryOperator<String> binaryOperator = (s1, s2) -> s1 + s2;
    }


    static class Person {
        private Long id;
        private String name;

        public Person(Long id, String name) {
            this.id = id;
            this.name = name;
        }

        public Long getId() {
            return id;
        }

        public String getName() {
            return name;
        }
    }

    static class Employee extends Person {

        private Double salary;

        public Employee(Long id, String name, Double salary) {
            super(id, name);
            this.salary = salary;
        }

        public Double getSalary() {
            return salary;
        }
    }
}
